from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from time import sleep
from options import options
from service import service

dr=webdriver.Chrome(options=options,service=service)
url=r'http://172.16.22.105:8080/bsams/front/login.do'
dr.get(url)
dr.maximize_window()
sleep(3)
# 登录
# 任务id
dr.find_element(By.ID,'taskId').clear()
dr.find_element(By.ID,'taskId').send_keys('1')
sleep(1)
# 用户名
dr.find_element(By.ID,'loginName').clear()
dr.find_element(By.ID,'loginName').send_keys('liushun01')
sleep(1)
# 密码
dr.find_element(By.ID,'password').clear()
dr.find_element(By.ID,'password').send_keys('123123')
sleep(1)
# 验证码
dr.find_element(By.ID,'vericode').clear()
dr.find_element(By.ID,'vericode').send_keys('shtd')
sleep(1)
# 登录按钮
dr.find_element(By.XPATH,'//*[@id="fmedit"]/div[2]/div[6]/input').click()
sleep(1)

# 个人信息
# 修改电话号
dr.find_element(By.ID,'phone').clear()
dr.find_element(By.ID,'phone').send_keys('15239925866')
sleep(1)
# 保存按钮
dr.find_element(By.XPATH,'/html/body/div[2]/div/div[2]/div[2]/div[1]/form/table/tbody/tr[2]/td[3]/div/a').click()
sleep(2)
# 处理警告弹窗
# 获取本文
text=dr.switch_to.alert.text
print(text)
sleep(3)
# 点击确定
dr.switch_to.alert.accept()
sleep(3)
# 修改密码
dr.find_element(By.LINK_TEXT,'修改密码').click()
# 当前密码
dr.find_element(By.ID,'oldPassword').clear()
dr.find_element(By.ID,'oldPassword').send_keys('123456')
sleep(1)
# 新密码
dr.find_element(By.ID,'newPassword1').clear()
dr.find_element(By.ID,'newPassword1').send_keys('123123')
sleep(1)
# 确认密码
dr.find_element(By.ID,'newPassword2').clear()
dr.find_element(By.ID,'newPassword2').send_keys('123123')
sleep(1)
# 确定按钮
dr.find_element(By.XPATH,'//*[@id="cboxLoadedContent"]/div/div/div[2]/div[4]/div[1]').click()
sleep(1)
# 处理警告弹窗
# 获取本文
text=dr.switch_to.alert.text
print(text)
sleep(3)
# 点击确定
dr.switch_to.alert.accept()
sleep(3)
